package iac.gwt.plant.client.deviceobject;

import iac.gwt.client.IacDetailPanel;
import br.com.iswe.gwt.ui.client.QueryInfo;
import br.com.iswe.gwt.ui.client.RPCService;
import br.com.iswe.gwt.ui.client.RequestInfo;

import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.FocusWidget;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class XXX_DetailPanel extends RmDetailPanel {
	
	private Button closeButton;
	private Button saveButton;
	private Button deleteButton;
	
	// ## IMPORTANT :: -->> This queryInfo must contain the properties needed to populate the screen (during detail)
	protected QueryInfo queryInfoDetail = new QueryInfo(new String[]{ getIdProperty(), VERSION });
	
	protected RequestInfo requestInfoSave = new RequestInfo(new String[]{ getIdProperty(), VERSION });
	
	protected RPCService service = new RPCService(XXX_Constants.CONTROLLER_NAME);
	
	
	public XXX_DetailPanel() {
		final VerticalPanel verticalPanel = new VerticalPanel();
		initWidget(verticalPanel);
		verticalPanel.setSpacing(4);
		
		final AbsolutePanel absolutePanel = new AbsolutePanel();
		verticalPanel.add(absolutePanel);
		absolutePanel.setSize("540px", "170px");

		saveButton = new Button();
		absolutePanel.add(saveButton, 268, 11);
		saveButton.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				save();
			}
		});
		saveButton.setWidth("75px");
		saveButton.setText("Save");

		closeButton = new Button();
		absolutePanel.add(closeButton, 452, 11);
		closeButton.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				cancelClose();
			}
		});
		closeButton.setWidth("75");
		closeButton.setText("Close");

		deleteButton = new Button();
		absolutePanel.add(deleteButton, 359, 11);
		deleteButton.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				delete();
			}
		});
		deleteButton.setWidth("75");
		deleteButton.setText("Delete");

		

		//registra os componentes na formFactory
		setupScreen();
	}
	
	protected void setupScreen() {
		//hidden properties
		formFactory.buildProperty(VERSION);
		formFactory.addProperty(XXX_Constants.ID_PROPERTY, null);
		
		//configura os componentes visuais (campos) na form factory para manilupar esses dados
		//formFactory.addProperty(ROLE_TYPE, roleTypeListBox, ROLE_TYPE_CONTROLLER, ROLE_TYPE_ID, DESCRIPTION, new RequiredValidator("Role Type"));
		
		formFactory.loadListBoxes(service);
	}
	
	protected String getIdProperty() {
		return XXX_Constants.ID_PROPERTY;
	}
	
	protected RPCService getService(){
		return service;
	}
	
	protected RequestInfo getRequestInfoSave() {
		return requestInfoSave;
	}
	
	protected QueryInfo getQueryInfoDetail() {
		return queryInfoDetail;
	}
	
	protected FocusWidget getSaveButton() {
		return saveButton;
	}
	
	protected FocusWidget getDeleteButton() {
		return deleteButton;
	}
}
